package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.Productdetailsinfo;
import com.ysd.util.DBManager;

public class chafenDaoImpl {
	public List<Productdetailsinfo> Productdetailsinfo(int pid){
		List<Productdetailsinfo> list = new ArrayList<Productdetailsinfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from Productdetailsinfo where productid="+pid);
			while(rs.next()) {
				String productProductName = rs.getString("productProductName");
				int cid = rs.getInt("cid");
				String img = rs.getString("img");
				int productid = rs.getInt("productid");
				String productMaterial = rs.getString("productMaterial");
				int productPrice = rs.getInt("productPrice");
				int marketPrice = rs.getInt("marketPrice");
				String productBrand = rs.getString("productBrand");
				String color = rs.getString("color");
				String style = rs.getString("style");
				
				Productdetailsinfo  Productdetailsinfo = new Productdetailsinfo(productProductName, cid, img, productid, productMaterial, productPrice, marketPrice, productBrand, color, style);       
				list.add(Productdetailsinfo);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	} 
	public List<Productdetailsinfo> changpin(){
		List<Productdetailsinfo> list = new ArrayList<Productdetailsinfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from Productdetailsinfo ");
			while(rs.next()) {
				String productProductName = rs.getString("productProductName");
				int cid = rs.getInt("cid");
				String img = rs.getString("img");
				int productid = rs.getInt("productid");
				String productMaterial = rs.getString("productMaterial");
				int productPrice = rs.getInt("productPrice");
				int marketPrice = rs.getInt("marketPrice");
				String productBrand = rs.getString("productBrand");
				String color = rs.getString("color");
				String style = rs.getString("style");
				Productdetailsinfo  Productdetailsinfo = new Productdetailsinfo(productProductName, cid, img, productid, productMaterial, productPrice, marketPrice, productBrand, color, style);       
				list.add(Productdetailsinfo);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	} 
	public int deletexiangqing(int cId) {
		return DBManager.executeUpdate("DELETE from Productdetailsinfo where productid="+cId);
	}
}
